<template>
	<scroll-view class="content" scroll-y="true" @scrolltolower="getMore()">
		<view class="item" v-for="(item,index) in data" :key="index" @click="info(index)">
			<image :src="item.img" class="poster"></image>
			<text class="newsTime">{{$formatDateString(item.created_at)}}</text>
			<view class="line1"></view>
			<text class="newsTitle ellipsis">{{item.name}}</text>
			<view class="infoBtn">查看详情</view>
		</view>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				data: [],
				page: 1
			}
		},
		onLoad() {
			this.getData();
		},
		methods: {
			info(index) {
				if (this.data[index].uri) { //存在链接
					this.$navto.navto('/pages/webview/webview', {
						url: this.data[index].uri
					})
				} else {
					this.$navto.navto('/pages/news_info/news_info', {
						id: this.data[index].id
					})
				}
			},
			getMore() {
				console.log("加载更多")
				this.page++;
				this.getData();
			},
			getData() {
				this.$request.get(`articleIndex?page=${this.page}`).then(res => {
					this.data.push(...res.data.data);
				})
			}
		}
	}
</script>

<style lang="scss">
	.item {
		width: 670rpx;
		height: 770rpx;
		padding-left: 40rpx;
		padding-right: 40rpx;
		margin-top: 60rpx;
		border-bottom: 1rpx solid #dbdbdb;
		position: relative;
		display: flex;
		flex-direction: column;

		.infoBtn {
			position: absolute;
			right: 40rpx;
			bottom: 60rpx;
			width: 150rpx;
			height: 60rpx;
			line-height: 60rpx;
			text-align: center;
			border-radius: 30rpx;
			background: #121212;
			font-weight: 500;
			font-size: 16rpx;
			color: #FFFFFF;
			letter-spacing: 2rpx;
		}


		.newsTitle {
			margin-top: 30rpx;
			color: #121212;
			font-weight: 900;
			font-size: 26rpx;
		}

		.line1 {
			margin-top: 30rpx;
			width: 18rpx;
			height: 4rpx;
			background: #ff6e5d;
		}

		.newsTime {
			margin-top: 50rpx;
			font-weight: 700;
			font-size: 42rpx;
			color: #121212;

		}

		.poster {
			width: 100%;
			height: 420rpx;
		}
	}

	.item:last-child {
		border: none;
	}

	.content {
		width: 100%;
		height: 100vh;
	}
</style>